<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>支付接口管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel='stylesheet' type="text/css" href="../../extjs-4.1.0/resources/css/ext-all-gray.css"/>
<script type="text/javascript" src="../../extjs-4.1.0/ext-all.js"></script>
<script type="text/javascript" src="../../js/ux/data/PagingMemoryProxy.js"></script>
<script type="text/javascript" src="../../js/ux/form/SearchField.js"></script>
<script type="text/javascript" src="../../js/ux/ProgressBarPager.js"></script>
<script type="text/javascript" src="../../js/ux/RowExpander.js"></script>
<script src="../../js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="../../js/i18n.js"></script>
<script type="text/javascript" src="../../js/head.js"></script>
<script type="text/javascript" src="../business/common.js"></script>
<script type="text/javascript">
Ext.Loader.setConfig({
    enabled: true
});
Ext.QuickTips.init(true,{dismissDelay:600000});
Ext.require([
    'Ext.data.*',
    'Ext.panel.Panel',
    'Ext.view.View',
    'Ext.layout.container.Fit',
    'Ext.toolbar.Paging',
    'Ext.ux.form.SearchField',
	'Ext.ux.RowExpander',
    'Ext.selection.CheckboxModel',
	'Ext.ux.data.PagingMemoryProxy',
    'Ext.ux.ProgressBarPager'
]);


Ext.onReady(function() {
	var vmid=0;
    var params;
    MultiLang = (function() {
        return {
            init: function() {
                // load ExtJS locale
                params = getCookie("lang");
                i18n.set({
  				  lang: params, 
  				  path: '../../resources'
  				});
                if (params) {
                    var url = Ext.util.Format.format('../../extjs-4.1.0/locale/ext-lang-{0}.js', params);
                    Ext.Ajax.request({
                        url: url,
                        success: this.onLoadExtLocaleSuccess,
                        failure: this.onLoadExtLocaleFailure,
                        scope: this
                    });
                } else {
                	this.setup();
                }
            },
            onLoadExtLocaleSuccess: function(response) {
                try {
                    eval(response.responseText);
                } catch (e) {
                    //Ext.Msg.alert('Failure', e.toString());
                }
                this.setup();
            },
            onLoadExtLocaleFailure: function() {
                //Ext.Msg.alert('Failure', 'Failed to load locale file.');
                this.setup();
            },
            setup: function() {	
  Ext.define('Domain',{
	  extend:'Ext.data.Model',
	  fields:['id',{name:'name',mapping:'abbreviation'}]
  })          	
  Ext.define('PaymentDBConfig', {
      extend: 'Ext.data.Model',
      fields: ['id', 'partner', 'key','dataStatus','sellerEmail','domain',
    	  {name: 'createDate', mapping: 'createDate', type: 'date', dateFormat: 'time'},
    	  {name: 'domainName',mapping:'domain.abbreviation'}
    	  ],
      idProperty: 'id'
  });

  // create the Data Store
  var store = Ext.create('Ext.data.Store', {
      pageSize: pageSize,
      model: 'PaymentDBConfig',
      proxy: new Ext.data.proxy.Ajax({
      	url: path+'/../bss/payment!getAllPaymentInterfaceByPage.action',
		reader: {
              type: 'json',
              root: 'resultObject.result',
              totalProperty: 'resultObject.totalCount'
        },
        listeners:{
			exception:function(reader, response, error, eOpts){
				ajaxException(reader, response, error, eOpts );
			}
		}
      })
  });
  store.load();
  
  var domainStore=Ext.create('Ext.data.Store',{
      model: 'Domain',
      proxy: new Ext.data.proxy.Ajax({
      	url: path+'/../admin_mgmt/domain!getAllDomain.action',
		reader: {
              type: 'json',
              root: 'resultObject',
              totalProperty: 'resultObject.totalCount'
        }
      })
  });
  
  domainStore.load();

    var selModel = Ext.create('Ext.selection.CheckboxModel', {
        listeners: {
            selectionchange: function(sm, selections) {
                grid4.down('#removeButton').setDisabled(selections.length == 0);
            }
        }
    });
    var sm = Ext.create('Ext.selection.RowModel');
    var pluginExpanded = true;
    var grid = Ext.create('Ext.grid.Panel', {
        id:'button-grid',
        store: store,
        title:i18n._('BusinessManagement')+'&nbsp;&nbsp;>&nbsp;&nbsp;'+i18n._('PaymentInterfaceManagement'),
		layout:'fit',
		sortableColumns:false,
		margin:'0 0 0 0',
	    width:'100%',
		height:'100%',
        frame: true,
		border:false,
		simpleSelect :true,
     	selModel:sm,
        iconCls: 'icon-grid',
        viewConfig: {
            stripeRows: true,
			forceFit: true
        },
        columns:[
		{xtype: 'rownumberer',flex:0.1},
        {
            text: i18n._('domainName'),
            dataIndex: 'domainName',
            flex: 0.4
        },{
            text: i18n._('payKey'),
            flex: 0.5,
            dataIndex:'key'
        },{
        	text: i18n._('partner'),
            flex: 0.4,
            dataIndex:'partner'
        },{
        	text: i18n._('domainEmail'),
            flex: 0.4,
            dataIndex:'sellerEmail'
        },{
        	text: i18n._('status'),
        	flex:0.2,
        	dataIndex:'dataStatus',
        	renderer:function(value){
        		if(value==0){
        			return i18n._('Disable_ServiceCatalog');
        		}else if(value=1){
        			return i18n._('Enable');
        		}
        	}
        },{
            text: i18n._('createDate'),
            dataIndex: 'createDate',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s'),
            flex: 0.4
        }],
        columnLines: true,
		bbar: Ext.create('Ext.PagingToolbar', {
            store: store,
			pageSize: 16,
			displayInfo: true
        }),
        listeners:{
        	"itemdblclick":{
        		fn:function(){
        			viewDetail();
        		}
        	}
        },
        dockedItems: [ {
            xtype: 'toolbar',
            cls: 'toolbarCSS',
            items: [
			{
				xtype:'button',
  				margin:'0 0 0 0',
  				icon:'images/add_new.png',
  				text:'<font id="AddPaymentInterface" color="white" >' +i18n._("Add") + '</font>',
                listeners: {
					 "mouseout" : function() {
						 document.getElementById("AddPaymentInterface").style.color = "white";
					 },
					 "mouseover" : function() {
						 document.getElementById("AddPaymentInterface").style.color = "black";
					 }
						
				},
			    handler: function(e) {
			    	getSessionUser();
			    	addPaymentInterface();
            }},{
            	xtype:'button',
                text:'<font id="ModifyPaymentInterface" color="white">'+i18n._('modify')+'</font>',
                listeners: {
					 "mouseout" : function() {
						 document.getElementById("ModifyPaymentInterface").style.color = "white";
					 },
					 "mouseover" : function() {
						 document.getElementById("ModifyPaymentInterface").style.color = "black";
					 }
						
				},
                icon: 'images/edit_new.png',
                handler:function(){
                	getSessionUser();
                	modifyPaymentInterface();
            	}
				},
				{
					xtype:'button',
	                text:'<font id="enableBrand" color="white">'+i18n._('Enable')+'</font>',
	                listeners: {
						 "mouseout" : function() {
							 document.getElementById("enableBrand").style.color = "white";
						 },
						 "mouseover" : function() {
							 document.getElementById("enableBrand").style.color = "black";
						 }
							
					},
	                icon: 'images/enable.png',
	                handler:function(){
	                	getSessionUser();
	                	var rows=grid.getSelectionModel().getSelection();
	      				 if(rows.length > 0){
	      				 var piId=rows[0].get('id');
	      				 if(rows[0].get('dataStatus')!=0){
	      					Ext.MessageBox.show({
								  title: i18n._('notice'),
								 msg:i18n._('enablePaymentInterfaceTip'),
                                  icon:Ext.MessageBox.INFO,
                                  buttons: Ext.MessageBox.OK
   
								});
	      					return;
	      				 }
	      				 Ext.MessageBox.show({
	      							    title: i18n._('notice'),
	      								msg:i18n._('confirmEnableSC'),
	      			                   buttons: Ext.MessageBox.YESNO,
	      			                   icon: Ext.MessageBox.QUESTION,
	      			                   fn:function(e){
	      			                	   if(e=="no"){
	      			                		   return;
	      			                	   }else if(e=='yes'){
	      			                		   Ext.Ajax.request({
	      											url: path+'/../bss/payment!enablePaymentConfig.action',
	      											method: 'POST',
	      											params:{
	      											'id':piId
	      											},
	      											success:function(response){
	      					           					var result=Ext.JSON.decode(response.responseText);
	      					           					if(result.success==false){
	      					           						Ext.MessageBox.show({
	      				                                        title:i18n._('notice'),
	      					 	                               msg: result.resultMsg,
	      					 	                               icon:Ext.MessageBox.INFO,	 	           		  
	      					 	                               buttons: Ext.MessageBox.OK	 	                      
	      					 	           				});
	      					           					}else{
	      					           						Ext.MessageBox.show({
	      														  title: i18n._('notice'),
	      														 msg:i18n._('enableSCSuccess'),
	      				                                          icon:Ext.MessageBox.INFO,
	      				                                          buttons: Ext.MessageBox.OK
	      				           
	      														});
	      												store.load();
	      												}
	      											}
	      												});
	      			                	   }
	      			                	 
	      			                	}
	      			    		});	 	
	      					}else{
	      						 Ext.MessageBox.show({
	      							    title: i18n._('notice'),
	      							    msg:i18n._('please choose one column'),
	                                      icon:Ext.MessageBox.WARNING,
	                                      buttons: Ext.MessageBox.OK
	      						}); 
	      						return;
	      			    	}
	            	}
            	},
				{
					xtype:'button',
	                text:'<font id="deleteBrand" color="white">'+i18n._('Disable_ServiceCatalog')+'</font>',
	                listeners: {
						 "mouseout" : function() {
							 document.getElementById("deleteBrand").style.color = "white";
						 },
						 "mouseover" : function() {
							 document.getElementById("deleteBrand").style.color = "black";
						 }
							
					},
	                icon: 'images/disable.png',
	                handler:function(){
	                	getSessionUser();
	                	var rows=grid.getSelectionModel().getSelection();
	      				 if(rows.length > 0){
	      				 var piId=rows[0].get('id');
	      				if(rows[0].get('dataStatus')!=1){
	      					Ext.MessageBox.show({
								  title: i18n._('notice'),
								 msg:i18n._('disablePaymentInterfaceTip'),
                                  icon:Ext.MessageBox.INFO,
                                  buttons: Ext.MessageBox.OK
   
								});
	      					return;
	      				 }
	      				 Ext.MessageBox.show({
	      							    title: i18n._('notice'),
	      								msg:i18n._('confirmDisableSC'),
	      			                   buttons: Ext.MessageBox.YESNO,
	      			                   icon: Ext.MessageBox.QUESTION,
	      			                   fn:function(e){
	      			                	   if(e=="no"){
	      			                		   return;
	      			                	   }else if(e=='yes'){
	      			                		   Ext.Ajax.request({
	      											url: path+'/../bss/payment!disablePaymentConfig.action',
	      											method: 'POST',
	      											params:{
	      											'id':piId
	      											},
	      											success:function(response){
	      					           					var result=Ext.JSON.decode(response.responseText);
	      					           					if(result.success==false){
	      					           						Ext.MessageBox.show({
	      				                                        title:i18n._('notice'),
	      					 	                               msg: result.resultMsg,
	      					 	                               icon:Ext.MessageBox.INFO,	 	           		  
	      					 	                               buttons: Ext.MessageBox.OK	 	                      
	      					 	           				});
	      					           					}else{
	      					           						Ext.MessageBox.show({
	      														  title: i18n._('notice'),
	      														 msg:i18n._('disableSCSuccess'),
	      				                                          icon:Ext.MessageBox.INFO,
	      				                                          buttons: Ext.MessageBox.OK
	      				           
	      														});
	      												store.load();
	      												}
	      											}
	      												});
	      			                	   }
	      			                	 
	      			                	}
	      			    		});	 	
	      					}else{
	      						 Ext.MessageBox.show({
	      							    title: i18n._('notice'),
	      							    msg:i18n._('please choose one column'),
	                                      icon:Ext.MessageBox.WARNING,
	                                      buttons: Ext.MessageBox.OK
	      						}); 
	      						return;
	      			    	}
	            	}
            	},
            {xtype:'tbfill'},
            {
				xtype:'displayfield',
				hideLabel:true,
				value:'<span style="bottom:3px;position:relative;"><font color="white">'+i18n._('QuickSearch')+':'+'</font></span>'
			},
	        {
                xtype: 'searchfield',
                hideLabel:true,
				hasSearch:true,
				emptyText:i18n._('domainName'),
                store: store
				
			 }
            ]
        }]
    });
    
    function modifyPaymentInterface(){
    	var rows=grid.getSelectionModel().getSelection();
		 if(rows.length > 0){
			 var domainId=rows[0].get('domain')['id'];
			 var piId=rows[0].get('id');
			 var keyValue=rows[0].get('key');
			 var partnerValue=rows[0].get('partner');
			 var sellerEmailValue=rows[0].get("sellerEmail");
				var modifyPaymentInterfaceWin=Ext.create('Ext.window.Window', {
				    title:i18n._('modifyPaymentInterface'),
					layout:'fit',
				    height: 270,
				    constrain:true,
					modal:true,
				    width: 430,
					closable:false,
					tools:[{
					  type:'close',
					  handler:function(){
						  modifyPaymentInterfaceWin.destroy();
					  }
					}],
				    items: {  
				        xtype: 'form',
						height:'100%',
						width:'100%',
						id:'m_restForm',
				        border: false,
				        dockedItems: [{
				            xtype: 'toolbar',
				            dock: 'bottom',
				            ui: 'footer',
				            layout: {
				                pack: 'left'
				            },
				            items: [{
								margin:'0 0 0 140',
				                minWidth: 80,
							    text: i18n._('OK'),
				                handler:function(){
				                	if(Ext.getCmp("m_domainField").isValid()&&Ext.getCmp("m_keyField").isValid()&&Ext.getCmp("m_partnerField").isValid()&&Ext.getCmp("m_sellerEmailField").isValid()){
				                		Ext.Ajax.request({
											url: path+'/../bss/payment!modifyPaymentConfig.action',
											method: 'POST',
										jsonData:{
											'id':piId,
										    "domain":{
										    	"id":Ext.getCmp("m_domainField").getValue()
										    },
										    "key":Ext.getCmp("m_keyField").getValue(),
										    "partner":Ext.getCmp("m_partnerField").getValue(),
										    "sellerEmail":Ext.getCmp("m_sellerEmailField").getValue()
										},
										success: function (response) {
											var obj = Ext.decode(response.responseText);
				                	    	if(obj.success){　　　
												store.load();
											}else{
												showMsg(obj.resultMsg);   
											}
										}
								    }); 
				                		modifyPaymentInterfaceWin.destroy();
				                	}
				                }
								
				           }
				           ]
				        }],
				        items:[
				               {
						        	xtype:'combobox',
						        	margin:'20 0 0 30',
									width:300,
									id:"m_domainField",
									labelWidth:70,
						        	fieldLabel: i18n._('domainName'),
						        	store: domainStore,
						        	displayField: 'name',
						        	emptyText:i18n._('Please Select'),
						        	editable:false,
						        	allowBlank:false,
						            valueField: 'id',
						            value:domainId,
						        	forceSelection:true,
						        	validateOnBlur:true,
								    textValid: true,
								    validator: function(){
								        return this.textValid;
								    },
									listeners : {
								        'change': function(textfield,newValue,oldValue) {
								        	if(domainId!=newValue){
								        		Ext.Ajax.request({
										        	   url: path+'/../bss/payment!checkDomainDup.action',
											    	    jsonData: {
											    	        'id':newValue
											    	    },
											    	    scope: textfield,
											    	    success: function(response){
											    	    	var rs=Ext.JSON.decode(response.responseText);
											    	    	if(rs.resultObject==true){
									   	                  		this.textValid = true;
											    	    		this.clearInvalid();
											    	    	}else{
																this.textValid=i18n._('domainExist');
									                            this.markInvalid(i18n._('domainExist'));
											    	    	}
											    	    	}
										           });
								        	}else{
								        		this.textValid = true;
							    	    		this.clearInvalid();
								        	}
								         }       
								      }
								    
						         },{
						        	 xtype:'textfield',
						        	 id:'m_keyField',
						        	 fieldLabel:i18n._('payKey'),
						        	 margin:'20 0 0 30',
									 width:300,
									 maxLength:32,
									 enforceMaxLength:true,
									 regex:/^[0-9a-zA-Z]{32}$/,
									 regexText:i18n._('payKeyTip'),
									 emptyText:'由数字和字母组成的32位字符串',
									 value:keyValue,
									 labelWidth:70,
									 allowBlank:false
						         },{
						        	 xtype:'textfield',
						        	 id:'m_partnerField',
						        	 fieldLabel:i18n._('partner'),
						        	 margin:'20 0 0 30',
									 width:300,
									 regex:/^2088[0-9]{12}$/,
									 maxLength:16,
									 enforceMaxLength:true,
									 regexText:i18n._("partnerTip"),
									 emptyText:'以2088开头由16位纯数字组成的字符串',
									 value:partnerValue,
									 labelWidth:70,
									 allowBlank:false
						         },{
						        	 xtype:'textfield',
						        	 id:'m_sellerEmailField',
						        	 emptyText:'签约支付宝账号或卖家收款支付宝帐户',
						        	 fieldLabel:i18n._('domainEmail'),
						        	 margin:'20 0 0 30',
						        	 vtype: 'email',
									 width:300,
									 value:sellerEmailValue,
									 labelWidth:70,
									 allowBlank:false
						         }      
						]
				    }
				});
				modifyPaymentInterfaceWin.show();
		}else{
				Ext.MessageBox.show({
					    title: i18n._('notice'),
					    msg:i18n._('please choose one column'),
                       icon:Ext.MessageBox.WARNING,
                       buttons: Ext.MessageBox.OK
				}); 
				return;
	    	}
    }
    
    function addPaymentInterface(){
		var addPaymentInterfaceWin=Ext.create('Ext.window.Window', {
		    title:i18n._('addPaymentInterface'),
			layout:'fit',
		    height: 250,
			modal:true,
			constrain:true,
		    width: 430,
			closable:false,
			tools:[{
			  type:'close',
			  handler:function(){
				  addPaymentInterfaceWin.destroy();
			  }
			}],
		    items: {  
		        xtype: 'form',
				height:'100%',
				width:'100%',
				id:'restForm',
				fieldDefaults:{
					//msgTarget:'side',
					autoFitErrors:false
				},
		        border: false,
		        dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'left'
		            },
		            items: [{
						margin:'0 0 0 140',
		                minWidth: 80,
					    text: i18n._('OK'),
		                handler:function(){
		                	if(Ext.getCmp("domainField").isValid()&&Ext.getCmp("keyField").isValid()&&Ext.getCmp("partnerField").isValid()&&Ext.getCmp("sellerEmailField").isValid()){
		                		Ext.Ajax.request({
									url: path+'/../bss/payment!createPaymentConfig.action',
									method: 'POST',
								jsonData:{
								    "domain":{
								    	"id":Ext.getCmp("domainField").getValue()
								    },
								    "key":Ext.getCmp("keyField").getValue(),
								    "partner":Ext.getCmp("partnerField").getValue(),
								    "sellerEmail":Ext.getCmp("sellerEmailField").getValue()
								},
								success: function (response) {
									var obj = Ext.decode(response.responseText);
		                	    	if(obj.success){　　　
										store.load();
									}else{
										showMsg(obj.resultMsg);   
									}
								}
						    }); 
		                		addPaymentInterfaceWin.destroy();
		                	}
		                }
						
		           }
		           ]
		        }],
		        items:[
		         {
		        	xtype:'combobox',
		        	margin:'20 0 0 30',
					width:300,
					id:"domainField",
					labelWidth:70,
		        	//multiSelect:true,
		        	fieldLabel: i18n._('domainName'),
		        	store: domainStore,
		        	displayField: 'name',
		        	emptyText:i18n._('Please Select'),
		        	editable:false,
		        	allowBlank:false,
		            valueField: 'id',
		        	forceSelection:true,
		        	validateOnBlur:true,
				    textValid: true,
				    validator: function(){		
				    	return this.textValid;
 				    },
					listeners : {
				        'change': function(textfield,newValue,oldValue) {
				        		Ext.Ajax.request({
						        	   url: path+'/../bss/payment!checkDomainDup.action',
							    	    jsonData: {
							    	        'id':newValue
							    	    },
							    	    scope: textfield,
							    	    success: function(response){
							    	    	var rs=Ext.JSON.decode(response.responseText);
							    	    	if(rs.success&&(rs.resultObject==true)){
					   	                  		this.textValid = true;
							    	    		this.clearInvalid();
							    	    	}else{
												this.textValid=i18n._('domainExist');
					                            this.markInvalid(i18n._('domainExist'));
							    	    	}
							    	    	}
						           });
				           
				         }       
				      }
				    
		         },
		         {
		        	 xtype:'textfield',
		        	 id:'keyField',
		        	 fieldLabel:i18n._('payKey'),
		        	 emptyText:'由数字和字母组成的32位字符串',
		        	 margin:'20 0 0 30',
		        	 regex:/^[0-9a-zA-Z]{32}$/,
					 regexText:i18n._('payKeyTip'),
					 maxLength:32,
					 enforceMaxLength:true,
					 width:300,
					 labelWidth:70,
					 allowBlank:false
		         },{
		        	 xtype:'textfield',
		        	 id:'partnerField',
		        	 fieldLabel:i18n._('partner'),
		        	 margin:'20 0 0 30',
		        	 emptyText:'以2088开头由16位纯数字组成的字符串',
		        	 regex:/^(2088)([0-9]{12})$/,
					 regexText:i18n._("partnerTip"),
					 maxLength:16,
					 enforceMaxLength:true,
					 width:300,
					 labelWidth:70,
					 allowBlank:false
		         },{
		        	 xtype:'textfield',
		        	 id:'sellerEmailField',
		        	 vtype:"email",
		        	 emptyText:'签约支付宝账号或卖家收款支付宝帐户',
		        	 fieldLabel:i18n._('domainEmail'),
		        	 margin:'20 0 0 30',
					 width:300,
					 labelWidth:70,
					 allowBlank:false
		         }      
				]
		    }
		});
		addPaymentInterfaceWin.show();
    }

Ext.create('Ext.Viewport',{
	 layout:'fit',
	 items: grid
	});
            }
        };
    })();

    MultiLang.init();
    
});

function getCookie(name){
         var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
         if(arr != null) return unescape(arr[2]);
		 return null;
 }

</script>
 </head>

 <body>
  
 </body>
</html>
